const QB = require('../control/questionBase');


async function questionBaseList(req,res){

}


async function addquestionbase(req,res){
    const {user,qb} = req.body;
    //res.send("OK")
    let a = await QB.createQuestionBase(qb,user);
    console.log(a)
    res.send(a);
}

async function questionbaselist(req,res){
    const {page,pageSize} = req.query
    console.log(req.query)
    //console.log(page,pageSize)
    let a = await QB.QuestionBaseList(page,pageSize);
    res.send(a)
}

async function myquestionbaselist(req,res){
    const {page,pageSize,username} = req.query
    console.log(req.query)
    //console.log(page,pageSize)
    let a = await QB.myQuestionBaseList(page,pageSize,username);
    res.send(a)
}


async function updataquestionbase(req,res){

}

async function deletequestionbase(req,res){
    const { username,qb_id } = req.body;
    //console.log(req.body);
    //判断qb_id是否为数组而决定是否要进行转换，最终会得到一个以原数据为基础的数组
    let qb_ids = Array.isArray(qb_id) ? qb_id:[qb_id];
    console.log(qb_ids)
    let a = await QB.deleteQuestionBase(username,qb_ids)
    // console.log(a)
    res.send(a);
}

async function addquestion(req,res){
    const {questionArray,QBid,username} = req.body;
    let a = await QB.addQuestions(username,QBid,questionArray);
    res.send(a)

}

async function questionlist(req,res){
    const {username,qb_id,page,pagesize} = req.query
    let result =await QB.questionList(username,qb_id,page,pagesize);
    res.send(result);
}

async function delquestion(req,res){

}

module.exports = {
    addquestionbase,
    questionbaselist,
    myquestionbaselist,
    updataquestionbase,
    deletequestionbase,
    addquestion,
    questionlist,
    delquestion
}